<template>
  <div class="profile-container">
    <!-- 侧边导航栏 -->
    <el-aside width="240px" class="sidebar">
      <div class="logo">
        <span class="logo-text">智周万物</span>
      </div>
      <el-menu
        default-active="/profile"
        class="sidebar-menu"
        background-color="#f5f7fa"
        text-color="#333"
        active-text-color="#039be5"
        router
      >
        <el-menu-item index="/">
          <el-icon><Home /></el-icon>
          <span>AI聊天</span>
        </el-menu-item>
        <el-menu-item index="/history">
          <el-icon><History /></el-icon>
          <span>历史记录</span>
        </el-menu-item>
        <el-menu-item index="/profile">
          <el-icon><User /></el-icon>
          <span>个人中心</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <!-- 主内容区 -->
    <el-main class="main-content">
      <div class="page-header">
        <h1>个人中心</h1>
      </div>

      <!-- 个人信息卡片 -->
      <div class="profile-card">
        <div class="profile-info">
          <div class="avatar-section">
            <el-avatar class="user-avatar">
              <img :src="userInfo.avatar" alt="用户头像">
            </el-avatar>
            <el-button type="text" class="change-avatar-btn" @click="changeAvatar">更换头像</el-button>
          </div>

          <el-form ref="profileForm" :model="userInfo" class="profile-form">
            <el-form-item label="账号名称" prop="username">
              <el-input v-model="userInfo.username" readonly placeholder="请输入账号名称"></el-input>
            </el-form-item>

            <el-form-item label="生日" prop="birthday">
              <el-date-picker
                v-model="userInfo.birthday"
                type="date"
                placeholder="选择生日"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
              ></el-date-picker>
            </el-form-item>

            <el-form-item label="性别" prop="gender">
              <el-radio-group v-model="userInfo.gender">
                <el-radio label="male">男</el-radio>
                <el-radio label="female">女</el-radio>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="职业" prop="occupation">
              <el-select v-model="userInfo.occupation" placeholder="请选择职业">
                <el-option label="学生" value="student"></el-option>
                <el-option label="教师" value="teacher"></el-option>
                <el-option label="工程师" value="engineer"></el-option>
                <el-option label="设计师" value="designer"></el-option>
                <el-option label="其他" value="other"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item class="form-actions">
              <el-button type="primary" @click="saveProfile">保存</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-main>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { Home, History, User } from '@element-plus/icons-vue'

// 用户信息数据
const userInfo = reactive({
  avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
  username: 'admin',
  birthday: '2000-01-01',
  gender: 'female',
  occupation: 'student'
})

// 保存个人信息
const saveProfile = () => {
  // 在实际应用中，这里会调用API保存用户信息
  ElMessage.success('个人信息保存成功')
}

// 更换头像（模拟）
const changeAvatar = () => {
  // 模拟头像更换
  const newAvatars = [
    'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    'https://cube.elemecdn.com/1/19/752ed4e8d6629b311805a6c99845fpng.png',
    'https://cube.elemecdn.com/2/16/80d61ff4965f72a93243269643af8png.png'
  ]
  const randomIndex = Math.floor(Math.random() * newAvatars.length)
  userInfo.avatar = newAvatars[randomIndex]
  ElMessage.success('头像更换成功')
}
</script>

<style scoped>
.profile-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background-color: #f5f7fa;
  border-right: 1px solid #e5e9f2;
  height: 100%;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #e5e9f2;
  padding: 0 20px;
}

.logo-text {
  font-size: 18px;
  font-weight: bold;
  color: #039be5;
}

.sidebar-menu {
  border-right: none;
  height: calc(100% - 60px);
}

.main-content {
  padding: 20px;
  overflow-y: auto;
  background-color: #f9fafc;
}

.page-header {
  margin-bottom: 30px;
}

.page-header h1 {
  font-size: 24px;
  color: #333;
  margin: 0;
}

.profile-card {
  background-color: #fff;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.profile-info {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar-section {
  margin-bottom: 30px;
  text-align: center;
}

.user-avatar {
  width: 100px;
  height: 100px;
  margin-bottom: 10px;
}

.change-avatar-btn {
  color: #039be5;
}

.profile-form {
  width: 100%;
  max-width: 600px;
}

.el-form-item {
  margin-bottom: 25px;
}

.el-form-item__label {
  font-size: 14px;
  color: #666;
}

.form-actions {
  display: flex;
  justify-content: center;
  margin-top: 30px;
}
</style>